package com.gsn.engine.gdx;

import com.badlogic.gdx.assets.loaders.resolvers.ResolutionFileResolver;
import com.badlogic.gdx.files.FileHandle;
import com.badlogic.gdx.graphics.g2d.ParticleEffect;
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
import com.badlogic.gdx.scenes.scene2d.Actor;

public class GsnParticleActor extends Actor {
	private static final String tag = "GsnParticleActor";

	public static ParticleEffect loadParticleEffect(ResolutionFileResolver resolver, String filePath){
		ParticleEffect effect = new ParticleEffect();
		FileHandle t1 = resolver.resolve(filePath);
		FileHandle t2 = t1.parent();
//		Gdx.app.log(tag, t1.path());
//		Gdx.app.log(tag, t2.path());
		effect.load(t1, t2);
		return effect;
	}
	
	
	ParticleEffect effect;
	
	public GsnParticleActor(ParticleEffect effect) {
		this.effect = new ParticleEffect(effect);
	}
	
	public void allowCompletion(){
		effect.allowCompletion();
	}
		
	public void setPostition(float x, float y){
		this.effect.setPosition(x, y);
	}
	
	public boolean isCompleted(){
		return effect.isComplete();
	}
	
	@Override
	public void draw(SpriteBatch batch, float parentAlpha) {
		// TODO Auto-generated method stub		
		effect.draw(batch);		
	}
	
	public void setDuration(int dur){
		effect.setDuration(dur);
	}
	
	@Override
	public void act(float delta) {
		// TODO Auto-generated method stub
		super.act(delta);
		effect.update(delta);
		if (effect.isComplete())
			remove();
	}
	
	public void update(float delta){
		effect.update(delta);
	}

	@Override
	public Actor hit(float x, float y) {
		// TODO Auto-generated method stub
		return null;
	}

	public void start() {
		effect.start();
		//effect.allowCompletion();
		
	}
	

}
